package GUI;

import javax.swing.JPanel;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.ArrayList;

@SuppressWarnings("serial")
/**
 * Abstract side bar 
 * @author Benny
 *
 */
public class SideBar extends JPanel {

	JButton btnLogout;
	JButton btnExit;
	public MainFrame mf;
	/**
	 * Create the panel.
	 * @param M Instance of the main Frame of the program
	 */
	public SideBar(MainFrame M) {
		setLayout(null);
		this.mf=M;
		
		
		btnExit = new JButton("Exit");
		btnExit.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				ArrayList<Object> send1 = new ArrayList<>();
				send1.add("20");
				send1.add(mf.logged_in_user.id);
				mf.client.accept(send1);
				mf.dispose();
			}
		});
		btnExit.setBounds(10, 532, 160, 23);
		add(btnExit);
		
		btnLogout = new JButton("LogOut");
		btnLogout.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				mf.sb.setVisible(false);
				mf.lg.setVisible(true);
				mf.lg.btnLogin.setEnabled(true);
				mf.lblConnectedToServer.setVisible(true);
				ArrayList<Object> send1 = new ArrayList<>();
				send1.add("20");
				send1.add(mf.logged_in_user.id);
				mf.client.accept(send1);
				hideall();
			}
		});
		btnLogout.setBounds(10, 498, 160, 23);
		add(btnLogout);
		this.setSize(185, 580);

		
		this.mf=M;			
		
	}
	  /**
	   * hide all the panels	
	   */
	  public void  hideall(){
		  
			mf.librarianMain.searchBook.setVisible(false);
			mf.librarianMain.bookReturn.setVisible(false);
			mf.librarianMain.manualExtend.setVisible(false);
			mf.librarianMain.registerNewUser.setVisible(false);
			mf.librarianMain.viewUser.setVisible(false);
			mf.librarianMain.bookBorrow.setVisible(false);
			mf.librarianMain.addBook.setVisible(false);
			mf.userMain.viewUser.setVisible(false);
			mf.userMain.recentActivities.setVisible(false);
			mf.userMain.orderBook.setVisible(false);
			mf.userMain.extendBorrow.setVisible(false);
			mf.userMain.bookSearch.setVisible(false);
			mf.userMain.updateUser.setVisible(false);
			mf.managerMain.reports.setVisible(false);
			mf.managerMain.cardManaging.setVisible(false);
			mf.librarianMain.addBook.setVisible(false);
			mf.managerMain.activityGUI.setVisible(false);
			mf.managerMain.regBorrowGUI.setVisible(false);
	  }

}